package com.woniu.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.mall.VO.StoreDetailVO;
import com.woniu.mall.VO.StoreListVO;
import com.woniu.mall.mapper.MallCollectMapper;
import com.woniu.mall.mapper.MallStoreMapper;
import com.woniu.mall.pojo.MallCollect;
import com.woniu.mall.pojo.MallStore;
import com.woniu.mall.service.IMallCollectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Klaus
 * @since 2023-05-23
 */
@Service
public class MallCollectServiceImpl extends ServiceImpl<MallCollectMapper, MallCollect> implements IMallCollectService {
    @Resource
    private MallCollectMapper collectMapper;
    @Resource
    private MallStoreMapper storeMapper;

    @Override
    public List<StoreListVO> getCollectList(Integer userId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.select("store_id").eq("user_id", userId);
        List<Integer> storeIdList = collectMapper.selectObjs(wrapper);
        List<StoreListVO> storeList = new ArrayList<>();
        for (Integer sid : storeIdList) {
            StoreListVO store = storeMapper.getStoreVO(sid);
            storeList.add(store);
        }
        return storeList;
    }
}
